<?php


namespace BoojasrFramework\Service;


use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

class RouteManageService
{
    private $routeCollection;
    private $matcher;
    private $context;
    private $generator;

    public function addRoute($name,Route $route){
        $routes = $this->getRouteCollection();
        $routes->add($name,$route);
        return $routes;
    }

    public function getRouteCollection(){
        if (!$this->routeCollection){
            $this->routeCollection = new RouteCollection();
        }
        return $this->routeCollection;
    }

    public function getContext(){
        if (!$this->context){
            $this->context = new RequestContext();
        }
        return $this->context;
    }

    public function getMatcher(){
        if (!$this->matcher){
            $this->matcher = new UrlMatcher($this->getRouteCollection(), $this->getContext());
        }
        return $this->matcher;
    }

    public function getUrlGenerator(){
        if (!$this->generator){
            $this->generator = new UrlGenerator($this->getRouteCollection(), $this->getContext());
        }
        return $this->generator;
    }

}